import QtQuick
import QtMultimedia 6.3
import QtQuick.Controls

Window {
    id:root
    width: 640
    height: 480
    visible: true

    property string fileName: "";

    MediaDevices {
        id: mediaDevices
    }
    CaptureSession {
        camera: Camera {
            id: camera
            cameraDevice: mediaDevices.defaultVideoInput
            focusMode: Camera.FocusModeAutoNear
            active: true
        }
        imageCapture: ImageCapture {
                    id: imageCapture
                    onImageSaved: (id, fileName) => {
                        console.log("Image saved to:", fileName)
                        root.fileName = "file:///" + fileName
                        root.close();
                    }
                }
        videoOutput: videoOutput
    }

    VideoOutput {
        id: videoOutput
        // x: 10; y: 10; width: 600; height: 400
        anchors.fill: parent
        orientation: 360
    }

    Button {
            text: "Capture"
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: {
                imageCapture.captureToFile("captured_image46g5r41r5ga4gr4gerg51.jpg")
            }
        }
}
